package com.thoughtworks.merchantsguide.service;

import com.thoughtworks.merchantsguide.commodity.Matter;
import com.thoughtworks.merchantsguide.exception.InvalidCommodityException;

/**
 * Service method to calculate price.
 */
public class PriceService implements IPriceService {

	/**
	 * This method is used to calculate the price/unit of credit of a matter.
	 */
	@Override
	public long getPrice(Matter iMatter, long iQuantity) throws InvalidCommodityException {

		if (null != iMatter && iMatter.isValid()) {
			return iMatter.getValue() * iQuantity;
		} else {
			throw new InvalidCommodityException();
		}
	}

}
